
<%@ page import="com.diseaseInformation.Disease" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'disease.label', default: 'Disease')}" />
  <title><g:message code="default.create.label" args="[entityName]" /></title>

  <g:javascript library="prototype" />
    </head>
    <body>

<g:javascript>
  function test(e){
  var datas = eval("(" + e.responseText + ")") // evaluate JSON

  if (datas) { 
  var rselect = document.getElementById('sel1')

  // Clear all previous options 
  var l = rselect.length

  while (l > 0) { 
  l-- 
  rselect.remove(l) 
  }

  // Rebuild the select 
  for (var i=0; i < datas.length; i++) { 
  var data = datas[i] 
  var opt = document.createElement('option');
  //opt.text = data.name 
  //opt.value = data.id 
  opt.text = data[1] //name
  opt.value = data[0] //id
  if(i==0)
  opt.selected = "selected"
  try { 
  rselect.add(opt, null) 
  // standards compliant; doesn't work in IE 
  } catch(ex) 
  { rselect.add(opt) // IE only 
  } 
  } 
  }

  if(rselect.length>=1){
  if(rselect.length==1)
  rselect.size = 2
  else if(rselect.length==2){
  rselect.size = 2
  }
  else if(rselect.length==3)
  rselect.size = 3
  else
  rselect.size = 4

  rselect.style.visibility='visible'
  }else
  rselect.style.visibility='hidden'

  }


  function selecttag(event){
  var textArea = document.getElementById('data')
  var selec = document.getElementById('sel1')
  var s = textArea.value
  var s2 = s.replace(/_[^_]+$/g,"_"+selec.options[selec.selectedIndex].text);
  textArea.value = s2
  }
  
  function big(){
  var textArea = document.getElementById('data')
  var cur = textArea.selectionEnd
  textArea.value = textArea.value.substring(0,textArea.selectionStart)+"[b]"+textArea.value.substring(textArea.selectionStart,textArea.selectionEnd)+"[/b]"+textArea.value.substring(textArea.selectionEnd,textArea.value.length)
  textArea.selectionEnd = cur+3
  textArea.focus()
  }
  
  function dot(){
  var textArea = document.getElementById('data')
  var cur = textArea.selectionEnd
  textArea.value = textArea.value.substring(0,textArea.selectionStart)+"*"+textArea.value.substring(textArea.selectionStart,textArea.value.length)
  textArea.selectionEnd = cur+1
  textArea.focus()
  }

</g:javascript>






        <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
            <span class="menuButton"><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></span>
        </div>
        <div class="body">
            <h1><g:message code="default.edit.label" args="[entityName]" /></h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <g:hasErrors bean="${diseaseInstance}">
            <div class="errors">
                <g:renderErrors bean="${diseaseInstance}" as="list" />
            </div>
            </g:hasErrors>
            <g:form method="post" >
                <g:hiddenField name="id" value="${diseaseInstance?.id}" />
                <g:hiddenField name="version" value="${diseaseInstance?.version}" />
                <div class="dialog">
                    <table>
                        <tbody>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="name"><g:message code="disease.name.label" default="Name" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: diseaseInstance, field: 'name', 'errors')}">
                                    <g:textField name="name" value="${diseaseInstance?.name}" />
                                </td>
                            </tr>
                        
        <!--Button-->
        <tr>
          <td/>
          <td>
            <button type="button" onclick="big()"><b>B</b></button>
            <button type="button" onclick="dot()">List</button>
          </td>
        </tr>
        
        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="data"><g:message code="disease.data.label" default="Data" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: diseaseInstance, field: 'data', 'errors')}">


            <div class="block">
              <g:textArea name="data" class="textare" id="data" value="${diseaseInstance?.data}" wrap="off"
                          onkeyup="${remoteFunction(action:'findtag',onComplete:'test(e)',params:'\'value=\' + this.value')}"/>
              <g:select class="sel" id="sel1"
                        onclick="selecttag(event)"/>
            </div>
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                  <label for="disease_group"><g:message code="disease.disease_group.label" default="Diseasegroup" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: diseaseInstance, field: 'disease_group', 'errors')}">
                                    <g:select name="disease_group.id" from="${com.diseaseInformation.Disease_Group.list()}" optionKey="id" value="${diseaseInstance?.disease_group?.id}"  />
                                </td>
                            </tr>
                                               
                        </tbody>
                    </table>
                </div>
                <div class="buttons">
                    <span class="button"><g:actionSubmit class="save" action="update" value="${message(code: 'default.button.update.label', default: 'Update')}" /></span>
                    <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
                </div>
            </g:form>
        </div>
    </body>
</html>
